package com.quan.common.websocket;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.quan.common.base.bean.WebSocketMessage;
import com.quan.common.core.BaseController;

/**
 * WebSocket 前端控制器
 * 提供给前端调用
 * @author yhaoquan
 *
 */
@RestController
@RequestMapping("/websocket")
public class WebSocketSockJSController extends BaseController {
	
	@Autowired
	private SimpMessagingTemplate messagingTemplate ;
	
	/**
	 * 广播系统消息
	 * @param message
	 */
	@PostMapping(value = "/notification")
	public void notification(@RequestBody WebSocketMessage message) {
		logger.info("广播WebSocket消息：{}", message);
		this.messagingTemplate.convertAndSend("/topic/notification", JSON.toJSONString(message));
	}
	
	
}
